package com.lightkits.wms.domain.rawmatstorage;

import com.lightkits.framework.common.exception.LightKitsBizException;
import com.lightkits.framework.common.model.IResult;
import com.lightkits.framework.common.utility.object.ObjectUtil;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.wms.domain.rawmatstorage.service.RawMatStorageDomain;
import com.lightkits.wms.dto.rawmatstorage.RawMatStorageRequestType;
import com.lightkits.wms.dto.rawmatstorage.RawMatStorageResponseType;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * RawMatSorageExecutor
 *
 * @author jing.wei@hand-china.com
 * Created on 2019/4/20 23:36
 */
@Component
public class RawMatSorageExecutor implements ServiceExecutor<RawMatStorageRequestType,RawMatStorageResponseType> {
   @Autowired
   private RawMatStorageDomain rawMatStorageDomain;
    @Override
    public RawMatStorageResponseType service(RawMatStorageRequestType request){
        RawMatStorageResponseType response=new RawMatStorageResponseType();
        try{
            IResult result= rawMatStorageDomain.rawMatStorage(request.getMatStorageDTO());
            result.fill(response);
        }catch (LightKitsBizException e) {
            response.setSuccessful(false);
            String mes= StringUtils.substringAfterLast(e.getMessage(),":");
            response.setMessage(ObjectUtil.isNullOrEmpty(mes)?e.getMessage():mes);
        } catch (Exception e) {
            response.setSuccessful(false);
            response.setMessage("Raw Mat Storage error");
        }
        return response;
    }
}
